package com.example.demo.controller.system;

import com.example.demo.annoation.Log;
import com.example.demo.bean.AjaxRes;
import com.example.demo.bean.sysdict.SysDictTypeDO;
import com.example.demo.controller.BaseAdminController;
import com.example.demo.enums.BusinessType;
import com.example.demo.service.ISysDictTypeService;
import com.example.demo.dto.sysdict.SysDictTypePageReqVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping(value = "/system/dict_type")
@RestController
public class SysDictTypeController extends BaseAdminController {

    @Resource
    private ISysDictTypeService sysDictTypeService;

    @GetMapping("/list")
    public AjaxRes list(SysDictTypePageReqVO sysDictTypePageReqVO) {
        return AjaxRes.success(sysDictTypeService.list(sysDictTypePageReqVO));
    }

    @PostMapping("/insert")
    @Log(title = "新增字典", businessType = BusinessType.INSERT)
    public AjaxRes insert(@RequestBody SysDictTypeDO sysDictTypeDO) {
        return toAjax(sysDictTypeService.addSysDictType(sysDictTypeDO));
    }

    @DeleteMapping("/delete/{dictId}")
    @Log(title = "删除字典", businessType = BusinessType.DELETE)
    public AjaxRes delete(@PathVariable("dictId") Long dictId) {
        return toAjax(sysDictTypeService.deleteSysDictType(new SysDictTypeDO().setDictId(dictId)));
    }

    @PutMapping("/update")
    @Log(title = "修改字典", businessType = BusinessType.UPDATE)
    public AjaxRes update(@RequestBody SysDictTypeDO sysDictTypeDO) {
        return toAjax(sysDictTypeService.updateSysDictType(sysDictTypeDO));
    }

    @GetMapping("/{dictId}")
    public AjaxRes query(@PathVariable("dictId") Long dictId) {
        return AjaxRes.success(sysDictTypeService.getSysDictType(new SysDictTypeDO().setDictId(dictId)));
    }
}
